﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.RemoteCryptoTokenProvider
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using System;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Cryptography.X509Certificates;

namespace Microsoft.InfoCards
{
  internal sealed class RemoteCryptoTokenProvider : SecurityTokenProvider, IDisposable
  {
    private RemoteX509Token m_token;
    private X509Certificate2 m_certificate;
    private object m_sync;

    public RemoteCryptoTokenProvider(X509Certificate2 cert)
    {
      this.m_sync = new object();
      this.m_certificate = cert;
    }

    public void Dispose()
    {
      IDisposable token = (IDisposable) this.m_token;
      if (token == null)
        return;
      token.Dispose();
      this.m_token = (RemoteX509Token) null;
    }

    protected override SecurityToken GetTokenCore(TimeSpan timeout)
    {
      return (SecurityToken) this.InnerGetToken();
    }

    private X509SecurityToken InnerGetToken()
    {
      if (this.m_token == null)
      {
        lock (this.m_sync)
        {
          if (this.m_token == null)
            this.m_token = new RemoteX509Token(this.m_certificate);
        }
      }
      return (X509SecurityToken) this.m_token;
    }
  }
}
